var selectedRow;
$(function () {
    initScanQrCodePage('minApp', 'check', doPass, openDoUnPassPage, refreshQrCode);
});

// dataTable
$('#dataTable').on("click-row.bs.table", function (e, row, $element) {
    // checkBox 的勾选
    var index = $element[0].rowIndex - 1;
    $('#dataTable').bootstrapTable('check', index);
    $('#dataTable .success').removeClass('success');//去除之前选中的行的，选中样式
    $element.addClass('success');//添加当前选中的 success样式用于区别
    selectedRow = row;
    doRefreshLog();
});

function checkPass() {
    swalToastr('审核通过',  '确定通过审核吗？', 'warning', doPass, '审核通过');
}

/*审核通过*/
function doPass() {
    var postData = {
        batchId : $("#batchId").val()
    };
    $.ajax({
        type: 'post',
        url: basePath + 'checkOrgTeam/doPass?t=' + new Date().getTime(),
        dataType: 'json',
        contentType: "application/json",
        data: JSON.stringify(postData),
        success : function (data) {
            if (!data) {
                toastr.error('合并失败');
                return;
            }
            if (!data.isSuccess) {
                toastr.error(data.errorDesc);
                return;
            }
            if(data.isSuccess){
                doBack();
            }
        },
    });
}

function openDoUnPassPage() {
    $('#unPassModal').modal('show');
}

/*审核不通过*/
function doUnPass() {
    var reason = $('#reason').val();
    if (!reason) {
        toastr.error('原因不能为空');
        return;
    }
    var postData = {
        batchId : $("#batchId").val(),
        reason : reason
    };
    $.ajax({
        type: 'post',
        url: basePath + 'checkOrgTeam/doUnPass?t=' + new Date().getTime(),
        dataType: 'json',
        contentType: "application/json",
        data: JSON.stringify(postData),
        success : function (data) {
            if (!data) {
                toastr.error('不通过操作失败');
                return;
            }
            if (!data.isSuccess) {
                toastr.error(data.errorDesc);
                return;
            }
            if(data.isSuccess){
                doBack();
            }
        },
    });
}

/*关闭合并层*/
function closeMergeModal() {
    $("#mergeModal").modal('hide');
}

function closeUnPassModal() {
    $('#reason').val('');
    $("#unPassModal").modal('hide');
}

$('#unPassModal').on('hidden.bs.modal', function () {
    // 执行一些动作...
    $('#reason').val('');
});

/*返回*/
function doBack() {
    if(page && page == '1'){
        var str = '&docName=' + searchInfo.docName + '&teamName=' + searchInfo.teamName + '&timeInterval=' + searchInfo.timeInterval
            + '&checkType=' + searchInfo.checkType + '&orgCode=' + searchInfo.orgCode
            + '&isCheckExist=' + searchInfo.isCheckExist + '&isQueryExist=' + searchInfo.isQueryExist
            + '&orgName=' + searchInfo.orgName + '&pageNo=' + searchInfo.pageNo + '&pageSize=' + searchInfo.pageSize;
        window.location.href = basePath + 'checkOrgTeam/pendingCheckOrgTeamPage?t=' + new Date().getTime() + str;
    } else {
        var str = '&docName=' + searchInfo.docName + '&teamName=' + searchInfo.teamName + '&timeInterval=' + searchInfo.timeInterval + '&result=' + searchInfo.result
            + '&checkType=' + searchInfo.checkType + '&orgCode=' + searchInfo.orgCode
            + '&isCheckExist=' + searchInfo.isCheckExist + '&isQueryExist=' + searchInfo.isQueryExist
            + '&orgName=' + searchInfo.orgName + '&pageNo=' + searchInfo.pageNo + '&pageSize=' + searchInfo.pageSize;
        window.location.href = basePath + 'checkOrgTeam/checkedOrgTeamPage?t=' + new Date().getTime() + str;
    }
}

/*function openViewPage() {
    var postData = {
        teamCode : $("#teamCode").val(),
        id : $("#teamId").val(),
    };
    $.ajax({
        type: 'post',
        url: basePath + 'checkOrgTeam/getQrCode',
        dataType: 'json',
        contentType: "application/json",
        data: JSON.stringify(postData),
        success : function (data) {
            if(data.result){
                var content = data.content;
                $("#scanCode").attr("src",content.qrUrl);
                $("#_validNum").html(content.validNum);
                $("#scanQrCodePage").modal('show');
            }else{
                toastr.error(data.message);
            }
        },
        error: function (request) {
            toastr.error(common_system_error);
        }
    });
}*/

/*
function chageQRCode() {
    var postData = {
        teamCode : $("#teamCode").val(),
        id : $("#teamId").val(),
    };
    $.ajax({
        type: 'post',
        url: basePath + 'checkOrgTeam/getQrCode',
        dataType: 'json',
        contentType: "application/json",
        data: JSON.stringify(postData),
        success : function (data) {
            if(data.result){
                // console.log(data.content)
                //移除当前已生成数据
                $("#scanCode").attr("src",data.content.qrUrl);
            }else{
                toastr.error(data.message);
            }
        },
        error: function (request) {
            toastr.error(common_system_error);
        }
    });
}*/


//new
function openViewPage() {
    var url = basePath + 'checkOrgTeam/getQrCode';
    var data = {
        teamCode : $("#teamCode").val(),
        id : $("#teamId").val(),
    };
    doShowQrCode(url, data, 'minApp');
}

function refreshQrCode() {
    var url = basePath + 'checkOrgTeam/getQrCode';
    var data = {
        teamCode : $("#teamCode").val(),
        id : $("#teamId").val(),
    };
    doRefreshQrCode(url, data, 'minApp');
}